package cn.com.dhcc.ddi.task.dao;

import cn.com.dhcc.app.core.dao.BaseDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.CM;
import cn.com.dhcc.ddi.task.vo.TaskPeriod;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
/**
 * @类: TaskPeriodDao
 * @描述: 周期性任务Dao
 * @作者: 张洪涛
 * @日期: 2016年11月14日 下午3:46:16
 * @版权所有: 东华软件
 *@版本:1.0
 */
@Repository
public class TaskPeriodDao extends BaseDao {
	private static Logger logger = Log.getLogger(LOGTYPE.DDI);
	
	
	/**
	 * @方法: getTaskPeriod
	 * @描述: 获取周期性任务
	 * @param taskid 任务id
	 * @return
	 * @throws DaoException
	 */
	public TaskPeriod getTaskPeriod(String taskid) throws DaoException {
		String msg;
		String sql = "select * from "+SI_TABLE("t_ddi_task_period") + " where task_id=? ";
		try {
			TaskPeriod taskPeriod  =CM.getDao().getModule("", sql, TaskPeriod.class, new Object[]{taskid});
			if(taskPeriod!=null){
				return taskPeriod;
			}else{
				return null;
			}
		} catch (DaoException e) {
			msg = "获取表数据失败";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
	}

	/**
	 * 删除周期性任务
	 * @param  taskId 任务id
	 * @return 成功数
	 * @throws DaoException
	 */
	public int deleteByTaskId(String taskId) throws DaoException{
		String msg;
		String sql = "DELETE FROM "+SI_TABLE("t_ddi_task_period") + " WHERE task_id=? ";
		try {
			return CM.getDao().delete("删除周期性任务", sql, new Object[]{taskId});
		} catch (DaoException e) {
			msg = "删除周期性任务失败";
			throw new DaoException(msg, e);
		}
	}
}
